package com.lhf.springcloud.service;

import com.lhf.springcloud.DAO.StudentBasicDao;
import com.lhf.springcloud.DAO.StudentDao;
import com.lhf.springcloud.Entity.StudentBasicInfo;
import com.lhf.springcloud.Entity.StudentInfo;
import com.lhf.springcloud.config.StorageProperties;
import com.lhf.springcloud.exception.StorageException;
import com.lhf.springcloud.exception.StorageFileNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

/**
 * @ClassName: StorangeServiceImpl
 * @Description:
 * @Author: liuhefei
 * @Date: 2019/4/1
 * @blog: https://www.imooc.com/u/1323320/articles
 **/
@Service
public class StudentBasicDataImpl {


    @Autowired
    private StudentBasicDao studentBasicDao;

    public void addCourse(List<StudentBasicInfo> course) {
        for (int i=0;i<course.size();i++){
            String idCard = course.get(i).getIdCard();
            String studentBasicDataByIdCard = studentBasicDao.findStudentBasicDataByIdCard(idCard);
            if (studentBasicDataByIdCard==null){
                    studentBasicDao.addCourse(course.get(i));
            }else {
                continue;
            }

        }

    }

    public Map findAllStudentBasicData(Integer startPage,Integer endPage,String idCard,String teacherName) {
        if (idCard!=null&&idCard.equals("")){
            idCard=null;
        }
        if (teacherName!=null&&teacherName.equals("")){
            teacherName=null;
        }
        List<StudentBasicInfo> data = studentBasicDao.findAllStudentBasicData(startPage,endPage,idCard,teacherName);
        Integer count = studentBasicDao.findCount();
        Map map=new HashMap<>();
        map.put("data",data);
        map.put("count",count);
        return map;
    }

    public void updateData(String dataValue,String id,String dataName) {
        studentBasicDao.updateData(dataValue,id,dataName);
    }

    public List<StudentBasicInfo> findByIdCard(String idCard) {
        List<StudentBasicInfo> byIdCard = studentBasicDao.findByIdCard(idCard);
        return  byIdCard;
    }
}
